package com.stevenmoon.csdnplus.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.stevenmoon.csdnplus.R;
import com.stevenmoon.csdnplus.bean.headline.HeadlineListBean;
import com.stevenmoon.csdnplus.util.DateUtil;

import java.util.List;

/**
 * Created by WangJun on 2016/4/12.
 */
public class HeadlineColumnAdapter extends BaseRecyclerAdapter<HeadlineListBean> {

    public interface OnHeadlineItemClickListener{
        void OnHeadlineItemClick(HeadlineListBean item);
    }

    OnHeadlineItemClickListener mOnHeadlineItemClickListener;

    public HeadlineColumnAdapter(Context ctx, List<HeadlineListBean> list, OnHeadlineItemClickListener onHeadlineItemClickListener) {
        super(ctx, list);
        mOnHeadlineItemClickListener = onHeadlineItemClickListener;
    }

    @Override
    public int getItemLayoutId(int viewType) {
        return R.layout.item_headline_list;
    }

    @Override
    public void bindData(RecyclerViewHolder holder, int position, final HeadlineListBean item) {
        if(TextUtils.isEmpty(item.getPic())){
            holder.setVisible(R.id.titleImgIV,false);
        }else{
            holder.setVisible(R.id.titleImgIV,true);
            holder.setImageUrl(R.id.titleImgIV, item.getPic());
        }
        holder.setText(R.id.titleTV, item.getTitle())
                .setText(R.id.sourceTV, "来自：" + item.getSource_name())
                .setText(R.id.authorTV, item.getNick_name())
                .setText(R.id.dateTV, "分享于 " + DateUtil.getFlexibleDate(item.getCreated_at()))
                .setText(R.id.commentNumTV, item.getComments()+"")
                .setText(R.id.zanNumTV, item.getUps()+"");
        holder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnHeadlineItemClickListener.OnHeadlineItemClick(item);
            }
        });
    }

}
